package com.craftplay.service;

import com.craftplay.dao.EnrollMapper;
import com.craftplay.dao.UnitMapper;
import com.craftplay.model.Enroll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EnrollService {
    @Autowired
    private EnrollMapper enrollMapper;

    //根据某活动id列出该活动报名列表
    public List<Enroll> listAllUnit(int unitId) {
        return enrollMapper.selectAllUnitByUnitId(unitId);
    }
    //根据某活动id列出该活动所有尚未处理的报名列表
    public List<Enroll> listAllEnroll(int unitId) {
        return enrollMapper.selectByUnitId(unitId);
    }
    //根据申请人id列出该申请人所有已经通过的报名列表
    public List<Enroll> listAllPassedByActorId(int actorId) {
        return enrollMapper.selectAllPassedByActorId(actorId);
    }
    //根据申请人id列出该申请人尚未通过的报名列表
    public List<Enroll> listAllReqEnrollByActorId(int actorId) {
        return enrollMapper.selectReqEnrollByActorId(actorId);
    }
    //根据unitId返回通过的报名数
    public int getPassedEnrollNumByUnitId(int unitId) {
        List<Enroll> list = enrollMapper.getPassedEnrollByUnitId(unitId);
        return list.size();
    }


    public List<Enroll> getStatistic(int id) {
        return enrollMapper.getStatisticByUnitId(id);
    }

    public int updateEnroll(int id, int status) {
        return enrollMapper.updateStatus(id, status);
    }

    public List<Enroll> selectByActorIdAndUnitId(int id, int unitId) {
        return enrollMapper.selectByActorIdAndUnitId(id, unitId);
    }
    public int addEnroll(Enroll enroll) {
        return enrollMapper.insert(enroll);
    }

    //根据报名表主键獲取報名表信息
    public Enroll getEnrollActorId(int enrollId){
        return  enrollMapper.getEnrollById(enrollId);
    }

}
